const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers');

const { defineConfig } = require('@vue/cli-service');

let serverNum = 193;
let baseUrl;
if (serverNum == 30) {
  baseUrl = "http://192.168.100.30:9091";
} else if (serverNum == 246) {
  baseUrl = "http://192.168.101.246:9091";
} else if (serverNum == 28) {
  baseUrl = "http://192.168.100.28:900";
} else if (serverNum == 193) {
  baseUrl = "http://172.18.59.193:9911";
}

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: './',//公共路径,设为 ./ 可以避免打包后css与js路径不正确问题
  outputDir: 'dist',
  productionSourceMap: false,
  devServer: {
    proxy: {
      '/cstApi': {
        target: baseUrl, // 你请求的第三方接口
        changeOrigin: true, // 创建一个虚拟服务端，负责发送和接收数据，服务端和服务端进行数据的交互不会有跨域问题
        pathRewrite: { // 路径重写，替换target中的请求地址，也就是说以后你在请求直接写成/api即可。
          '^/cstApi': ''
        }
      },
    },
  },
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ]
  },
});
